#include <QCoreApplication>
#include <iostream>
#include <cstring>

extern "C" {
#include "kem.h"   // Kyber API
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    std::cout << "PQMagic Kyber KEM Test\n";

    // Kyber 参数
    uint8_t pk[KYBER_PUBLICKEYBYTES];
    uint8_t sk[KYBER_SECRETKEYBYTES];
    uint8_t ct[KYBER_CIPHERTEXTBYTES];
    uint8_t ss[KYBER_SSBYTES];
    uint8_t ss2[KYBER_SSBYTES];

    // 生成密钥对
    crypto_kem_keypair(pk, sk);

    // 使用公钥加密得到 (ct, ss)
    crypto_kem_enc(ct, ss, pk);

    // 使用私钥解密得到 ss2
    crypto_kem_dec(ss2, ct, sk);

    // 验证
    bool ok = (memcmp(ss, ss2, KYBER_SSBYTES) == 0);
    std::cout << "Kyber KEM correctness: " << (ok ? "PASS" : "FAIL") << std::endl;

    return 0;
}
